package com;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.PooledByteBufAllocator;
import io.netty.buffer.UnpooledDirectByteBuf;

import java.nio.charset.StandardCharsets;

public class ByteDmeo {
    public static void main(String[] args) {
       // ByteBuf buf = new

        UnpooledDirectByteBuf buf = new UnpooledDirectByteBuf(new PooledByteBufAllocator(),0,127);


        byte b = Integer.valueOf(45087).byteValue();
        byte[] bytes = intToByte4(Integer.valueOf(45087));
        buf.writeBytes(bytes);
        long l = buf.readUnsignedInt();

        buf.writeBytes("00045087".getBytes(StandardCharsets.UTF_8));
        short unsignedByte = buf.getUnsignedByte(0);
        unsignedByte = buf.getUnsignedByte(1);
        unsignedByte = buf.getUnsignedByte(2);
        unsignedByte = buf.getUnsignedByte(7);

        unsignedByte = buf.getUnsignedByte(0);
        int unsignedShort = buf.getUnsignedShort(0);
        buf.getUnsignedMedium(0);
        long UnsignedInt = buf.getUnsignedInt(0);
        long aLong = buf.getLong(7);


        System.out.println(unsignedByte);


    }
    /**
     * int整数转换为4字节的byte数组
     *
     * @param i  整数
     * @return byte数组
     */
    public static byte[] intToByte4(int i) {
        byte[] targets = new byte[4];
        targets[3] = (byte) (i & 0xFF);
        targets[2] = (byte) (i >> 8 & 0xFF);
        targets[1] = (byte) (i >> 16 & 0xFF);
        targets[0] = (byte) (i >> 24 & 0xFF);
        return targets;
    }
}
